
#include "gkt_event.h"
#include "gkt_user.h"
#include "window_menu_user_add.h"
#include "window_common.h"

enum {
	WIDGET_ID_LIST = 0,
	WIDGET_ID_MAX
};

enum {
	WIDGET_ID_LIST_ITEM_ADD_ADMIN_USER = 0,
	WIDGET_ID_LIST_ITEM_ADD_NORMAL_USER,
	WIDGET_ID_LIST_ITEM_SERIAL_NUM_DELETE_USER,
	WIDGET_ID_LIST_ITEM_GROUP_DELETE_USER,
	WIDGET_ID_LIST_ITEM_MAX
};

static const gkt_widget_list_item_s sc_window_menu_user_manage_list_items[] = {
	[WIDGET_ID_LIST_ITEM_ADD_ADMIN_USER] = GKT_WIDGET_LIST_STATIC_ITEM(
			WINDOW_VOICE_COMBINED_ID(add_admin_user), 
			GKT_USER_AUTH_ADMIN),
	[WIDGET_ID_LIST_ITEM_ADD_NORMAL_USER] = GKT_WIDGET_LIST_STATIC_ITEM(
			WINDOW_VOICE_COMBINED_ID(add_normal_user), 
			GKT_USER_AUTH_NORMAL),
	[WIDGET_ID_LIST_ITEM_SERIAL_NUM_DELETE_USER] = GKT_WIDGET_LIST_STATIC_ITEM(
			WINDOW_VOICE_COMBINED_ID(serial_number_delete), 
			WINDOW_ID_user_delete_serial_number),
	[WIDGET_ID_LIST_ITEM_GROUP_DELETE_USER] = GKT_WIDGET_LIST_STATIC_ITEM(
			WINDOW_VOICE_COMBINED_ID(group_delete), 
			WINDOW_ID_menu_user_delete_group)
};

#define WINDOW_MENU_MENU_USER_MANAGE_LIST_ITEM_NUMS	\
	sizeof(sc_window_menu_user_manage_list_items) / sizeof(gkt_widget_list_item_s)

static const gkt_widget_list_attr_s sc_window_menu_user_manage_list_attr = 
	GKT_WIDGET_LIST_STATIC_ATTR(WINDOW_MENU_MENU_USER_MANAGE_LIST_ITEM_NUMS, 
		sc_window_menu_user_manage_list_items);

GKT_WINDOW_WIDGET_DESCS_DEFINE(menu_user_manage) = {
	[WIDGET_ID_LIST] = GKT_WIDGET_LIST_DESC(0, &sc_window_menu_user_manage_list_attr),
};

typedef struct _window_menu_user_manager {
	window_user_add_data_s	add_data;
} window_menu_user_manager_s;
static window_menu_user_manager_s s_menu_user_manager;

static int window_menu_user_manage_event_handler(
				uint32_t major_type, uint32_t minor_type, 
				uint32_t id, uint32_t data)
{
	int retval = GKT_EVENT_HANDLE_CONTINUE;

	switch(major_type) {
		case GKT_EVENT_WINDOW:
			if (minor_type == GKT_WINDOW_ACTIVE)
				window_common_mask_except_number_repeat_return(
						WINDOW_MENU_MENU_USER_MANAGE_LIST_ITEM_NUMS);
			break;
		case GKT_EVENT_WIDGET:
			if (minor_type == GKT_WIDGET_EVENT_CLICK) {
				if (data <= WIDGET_ID_LIST_ITEM_ADD_NORMAL_USER) {
					s_menu_user_manager.add_data.authority = 
						sc_window_menu_user_manage_list_items[data].data;
					s_menu_user_manager.add_data.type = GKT_USER_TYPE_MAX;
					s_menu_user_manager.add_data.user_index = -1;

					gkt_window_show(WINDOW_ID_menu_user_add_type, 
							(uint32_t)&s_menu_user_manager.add_data);
				}
				else if (data == WIDGET_ID_LIST_ITEM_SERIAL_NUM_DELETE_USER) {
					gkt_window_show(sc_window_menu_user_manage_list_items[data].data, 0);
				}
				else {
					gkt_window_show(sc_window_menu_user_manage_list_items[data].data,
							GKT_USER_AUTH_NORMAL);
				}

				retval = GKT_EVENT_HANDLE_COMPLETE;
			}
			break;						
		default:	
			break;
	}

	return retval;
}

GKT_WINDOW_DESC_DEFINE(menu_user_manage);

